package com.example.myapplication;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity{

    private Button btn_comfirm,btn_login,btn_sign;
    private EditText et_name, et_id, et_phone, et_passwd;
    private ArrayList<String> hobbys = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_comfirm = findViewById(R.id.btn_confirm);
        btn_login = findViewById(R.id.btn_login);
        btn_sign = findViewById(R.id.btn_sign);
        et_name = findViewById(R.id.et_name);
        et_id = findViewById(R.id.et_id);
        et_phone = findViewById(R.id.et_phone);
        et_passwd = findViewById(R.id.et_passwd);

//        切换到登录页面
        btn_login.setOnClickListener((v)->{
            Intent intent = new Intent();
            intent.setClass(MainActivity.this,LoginActivity.class);
            startActivity(intent);
        });

//        注册成功跳转到登录页面
        btn_sign.setOnClickListener((v)->{
            String name = et_name.getText().toString().trim();
            String id = et_id.getText().toString().trim();
            String phone = et_phone.getText().toString().trim();
            String password = et_passwd.getText().toString().trim();

            if (name.isEmpty() || id.isEmpty() || phone.isEmpty() || password.isEmpty()) {
                Toast.makeText(MainActivity.this, "请填写完整的注册信息", Toast.LENGTH_SHORT).show();
                return;
            }

            Intent intent = new Intent();
            intent.setClass(MainActivity.this,LoginActivity.class);
            // 传递注册信息
            intent.putExtra("username", name);
            intent.putExtra("password", password);
            intent.putExtra("phone", phone);
            intent.putExtra("id", id);
            
            startActivity(intent);
            Toast.makeText(MainActivity.this, "注册成功，请登录", Toast.LENGTH_SHORT).show();
        });

//        用户协议确认
        btn_comfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 创建确认对话框
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

                // 设置对话框标题和内容
                builder.setTitle("用户协议确认");
                builder.setMessage("请您认真查阅用户协议内容，并选择是否同意接受用户协议。");

                // 设置确定按钮
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int which) {
                        // 用户点击确定后的处理逻辑
                        Toast.makeText(MainActivity.this, "已同意用户协议", Toast.LENGTH_SHORT).show();
                    }
                });

                // 设置取消按钮
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int which) {
                        // 用户点击取消后的处理逻辑
                        Toast.makeText(MainActivity.this, "已拒绝用户协议", Toast.LENGTH_SHORT).show();
                    }
                });

                // 显示对话框
                builder.show();
            }
        });
    }
}

//        传值（把注册信息传到登录页面）
//        btn_sign.setOnClickListener((v)->{
//            Intent intent = new Intent(MainActivity.this,LoginActivity.class);
//            Bundle bundle = new Bundle();
//            bundle.putString("用户名",etname.getText().toString());
//            bundle.putString("密码",etpasswd.getText().toString());
//            bundle.putString("电话",etphone.getText().toString());
//
//            int selectedId = radio_sex.getCheckedRadioButtonId();
//            RadioButton selectedRadioButton = findViewById(selectedId);
//            String gender = selectedRadioButton.getText().toString();
//            bundle.putString("角色", gender);
//
//            bundle.putStringArrayList("hobbys",hobbys);
//            intent.putExtras(bundle);
//            startActivity(intent);
//        });
